import { _decorator, Component, Node, Vec3, sp, Prefab, CCFloat, utils } from 'cc';
import { poolManager } from '../../../../Framework/Scripts/Managers/poolManager';
import myUtil from '../../../../Framework/Scripts/Utils/myUtil';


import MapNavAgent from '../MapNavAgent';
import { boss_aoeBomb } from './boss_aoeBomb';
const { ccclass, property } = _decorator;
//从天而降
@ccclass('boss_aoe')
export class boss_aoe extends Component {

    @property({ type: Prefab, displayName: "落地爆炸" })
    private boomNode: Prefab = null

    @property({ type: CCFloat, displayName: "伤害" })
    public hitNum: number = 100
    private move: MapNavAgent = null
    private pathArr = new Array()

    private howHit:Node=null

    private fun:Function=null


    start() {

    }

    onLoad() {
        this.move = this.node.getComponent(MapNavAgent)



    }

    public init(warmingPos: Vec3,howHit:Node, speed: number,fun?:Function) {
        this.howHit=howHit

         
         if(fun){
            this.fun=fun
         }

        this.move.InitMapNavAgent(speed)

        const rZ:number=myUtil.Random(-30,30)
        this.node.setWorldPosition(warmingPos.x, warmingPos.y + 30, warmingPos.z+rZ)
        this.pathArr.push(warmingPos)
        this.move.NavOnRoad(this.pathArr, () => {
            this.bomb()
          //  console.log("技能落地");
    
          


        })



    }
   public bomb(){
    this.pathArr = []

    if (this.boomNode) {
        let boom: Node = poolManager.instance.getNode(this.boomNode, this.node.parent)

     
        
      
        boom.setWorldPosition(this.node.getWorldPosition())

        let boss_aoeBombTs:boss_aoeBomb=boom.getComponent(boss_aoeBomb)
        if(boss_aoeBombTs){
            boss_aoeBombTs.hitNum = this.hitNum
            boss_aoeBombTs.init(this.howHit)
        }
        if(this.fun){
            this.fun()
        }
        poolManager.instance.putNode(this.node)


    }
   }
    update(dt: number) {


    }
}

